﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using System.Text;
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Input;
using SqlServerMaintenanceSolution.Commands;
using Microsoft.Win32;
using SqlServerMaintenanceSolution.Models;
using System.Windows.Data;
using System.Windows.Controls;
using SqlServerMaintenanceSolution.Models.Enums;


namespace SqlServerMaintenanceSolution.ViewModels
{
    public class MainScreenViewModel : ViewModelBase, INotifyPropertyChanged
    {
        private DelegateCommand exitCommand;

        private SqlServerAuthentication _sqlServerAuthentication;
        private SqlServerInstance _sqlServerInstance;

        private IntegrityViewModel _integrityViewModel;

        public IntegrityViewModel IntegrityViewModel
        {
            get { return _integrityViewModel; }
            set
            {
                if (_integrityViewModel == value) return;
                _integrityViewModel = value;

                OnPropertyChanged("IntegrityViewModel");
            }
        }
        
        private DiskSpaceViewModel _diskSpaceViewModel;

        public DiskSpaceViewModel DiskSpaceViewModel
        {
            get { return _diskSpaceViewModel; }
            set
            {
                if (_diskSpaceViewModel == value) return;
                _diskSpaceViewModel = value;

                OnPropertyChanged("DiskSpaceViewModel");
            }
        }

        private IndexFragmentViewModel _indexFragmentViewModel;

        public IndexFragmentViewModel IndexFragmentViewModel
        {
            get { return _indexFragmentViewModel; }
            set
            {
                if (_indexFragmentViewModel == value) return;
                _indexFragmentViewModel = value;

                OnPropertyChanged("IndexFragmentViewModel");
            }
        }
        public ICommand ExitCommand
        {
            get
            {
                if (exitCommand == null)
                {
                    exitCommand = new DelegateCommand(Exit);
                }
                return exitCommand;
            }
        }

        private void Exit()
        {
            Application.Current.Shutdown();
        }

        public MainScreenViewModel()
        {
            
        }

        public MainScreenViewModel(SqlServerInstance sqlServerInstance, SqlServerAuthentication sqlServerAuthentication)
        {
            this._sqlServerAuthentication = sqlServerAuthentication;
            this._sqlServerInstance = sqlServerInstance;

            this.DiskSpaceViewModel = new DiskSpaceViewModel(sqlServerInstance, sqlServerAuthentication);
            this.IntegrityViewModel = new IntegrityViewModel(sqlServerInstance, sqlServerAuthentication);
            this.IndexFragmentViewModel = new IndexFragmentViewModel(sqlServerInstance, sqlServerAuthentication);
           
            
        }

        
       
        private void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
        public event PropertyChangedEventHandler PropertyChanged;
 

        #region Commands
        public ICommand ConnectClickCommand
        {
            get { return new DelegateCommand<object>(ConnectClick, CanClickConnect); }
        }

        private void ConnectClick(object context)
        {
           
        }

        private bool CanClickConnect(object context)
        {
            return false;
        }

        #endregion

       
    }
}
